@extends('layouts.admin')

@section('title', '部门管理-添加')

@section('style')
    <link rel="stylesheet" type="text/css" href="{{asset('lib/bootstrap/css/bootstrap.min.css')}}" />
    <link rel="stylesheet" type="text/css" href="{{asset('lib/bootstrap/css/bootstrap-combobox.css')}}" />
@endsection

@section('content')
    <article class="page-container">
        <form action="" method="post" class="form form-horizontal" id="form-department-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>部门名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="hidden" name="id" value="{{$editEntity['data']['id']}}"/>
                    <input type="text" class="input-text" value="{{$editEntity['data']['name']}}" placeholder="" id="name" name="name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>上级部门：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <select class="combobox input-large form-control" name="parent_id" id="parent_id">
                        <option value="0">--无--</option>
                        @foreach ($departments['data'] as $department)
                            <option value="{{$department['id']}}">{{$department['name']}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>主管领导：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <select class="combobox input-large form-control" name="leader_user_id" id="leader_user_id">
                        <option value="0">--无--</option>
                        @foreach ($users['data'] as $user)
                            <option value="{{$user['id']}}">{{$user['name']}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>电话：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$editEntity['data']['tel']}}" placeholder="" id="tel" name="tel">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>传真：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$editEntity['data']['fax']}}" placeholder="" id="fax" name="fax">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">部门职能：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea name="duty" id="duty" cols="" rows="" class="textarea"  placeholder="部门职能描述">{{$editEntity['data']['duty']}}</textarea>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
@endsection
@section('script')
    <script type="text/javascript" src="{{asset('lib/bootstrap/bootstrap-combobox.js')}}"></script>
    <script>
        $("#parent_id").val("{{$editEntity['data']['parent_id']}}");
        $("#leader_user_id").val("{{$editEntity['data']['leader_user_id']}}");
        $('.combobox').combobox();
        $(".input-text,.textarea").Huifocusblur();
        $(".textarea").Huitextarealength({
            minlength:0,
            maxlength:200.
        });
        $("#form-department-add").validate({
            rules:{
                name:{
                    required:true
                },
                tel:{
                    isTel:true
                },
                fax:{
                    isPhone:true,
                },
                duty:{
                    maxlength:200
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('personnel/department/edit')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("编辑成功!");
                            setTimeout(function(){
                                parent.refresh_department_tree();
                                layer_close();
                            },500);
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('编辑失败!');
                    }
                });
            }
        });
    </script>
@endsection